<?php
namespace app\admin\controller;
use app\admin\model\Platform as platformModel;
use app\admin\model\Adv;
use app\admin\model\Message;
use app\admin\model\AdvisoryType;
use think\Db;
class Platform extends BaseController
{
    public function __construct()
    {
        parent::__construct();
//        $this->adv = new Adv();
    }

    /**
     * 关于我们页面
     * @author wxy
     * @date   2018-08-03
     */
    public function index(){
        $platform = new platformModel;
        $rs = $platform->getList();

        $page = $rs->render();
        $count=count($rs);
        $this->assign("page",$page);
        $this->assign('rs',$rs);
        $this->assign('count',$count);
        return $this->fetch('aboutUs');
    }
    /**
     * 公告修改
     * @author wxy
     * @date   2018-08-03
     */
    public function about_edit(){
        $platform = new platformModel;
        if(input("post.")){
            return $platform->about_edit();
        }else{
            $rs = $platform->getById();
            $this->assign('rs',$rs);
            return $this->fetch('about_edit');
        }
    }
    //删除公告
    //* @author wxy
    public function about_del(){
        $id = input("post.id");
        $platform = new platformModel;
        $res = $platform->del($id);
        return $res;
    }
    //留言类型列表
    //* @author wxy
    public  function advisory_type()
    {
        $advisory = new AdvisoryType;
        $rs = $advisory->getList();
        $page = $rs->render();
        $count=count($rs);
        $this->assign("page",$page);
        $this->assign('rs',$rs);
        $this->assign('count',$count);
        return $this->fetch('advisory_type');
    }
    //留言类型修改
    //* @author wxy
    public  function advisory_type_eidt()
    {
        $advisory = new AdvisoryType;
        if(input("post.")){
            return $advisory->advisory_type_eidt();
        }else{
            if(input("get.id"))
            {
                $rs = $advisory->getById(input("get.id"));

            }else
            {
                $rs=array("id"=>"","advisory_name"=>"");
            }
            $this->assign('rs',$rs);
            return $this->fetch('advisory_type_eidt');
        }
        return $this->fetch('advisory_type_eidt');
    }

    //留言类型删除
    //* @author wxy
    public  function advisory_type_del()
    {
        $advisory = new AdvisoryType;
        $id = input("post.id");
        return $advisory->advisoryTypeDel($id);
    }

    // 添加公司简介
    public function add_intrduce()
    {
        $advistory = new AdvisoryType();
        if(input('post.')){
            $data = input('post.');
            // echo "<pre>";
            // print_r($data);
            $result = $advistory->add_intrduce($data);
            return $result;

        }else{
            // 获取数据
            $result = Db::name('intrduce')->order('id desc')->limit(1)->find();
            // htmlspecialchars($result['content']);
            $this->assign('result',$result);
            return $this->fetch();
        }
    }

    public function edit_intrduce()
    {
        $advistory = new AdvisoryType();
        $data = input('post.');
        // echo "<pre>";
        // print_r($data);
        $result = $advistory->edit_intrduce($data);
        return $result;
    }
    public function i_del()
    {
        $advisory = new AdvisoryType;
        $id = input("post.id");
        return $advisory->i_del($id);
    }



    // 公司介绍管理
    public function introduce()
    {
        $advisory = new AdvisoryType;
        $rs = $advisory->getIntrduceList();
        $page = $rs->render();
        $count=count($rs);
        $this->assign("page",$page);
        $this->assign('rs',$rs);
        $this->assign('count',$count);
        return $this->fetch();
    }






    /**
     * 留言列表
     * @author shilei
     * @date   2018-08-03
     */
    public function commonProblem(){
        $message = new Message;
        $rs = $message->getList();
        $page = $rs->render();
        $this->assign("page",$page);
        $this->assign('rs',$rs);
        return $this->fetch('commonProblem');
    }
    /**
     * 留言回复
     * @author shilei
     * @date   2018-08-03
     */
    public function commonProblem_edit(){
        $message = new Message;
        if(input("post.")){
            $data = input("post.");
            return $message->messageEdit($data);
        }else{
            $id = input("get.id");
            $where ['ad.id'] = $id;
            $rs = $message->getinfos($where);
            $this->assign('rs',$rs);
            // print_r($rs);
            //$this->assign('time',date('Y-m-d H:i:s'));
            return $this->fetch('commonProblem_edit');
        }
    }
    /**
     * 留言单个删除
     * @author shilei
     * @date   2018-08-03
     */
    public function commonProblem_del(){
        $message = new Message;
        $id = input("post.id");
        return $message->messageDel($id);
    }
    /**
     * 常见问题批量删除
     * @author shilei
     * @date   2018-08-03
     */
    public function commonProblem_delAll(){
        $message = new Message;
        return $message->messagedelAll();
    }

}
